home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / C++SIM / Examples / Queue.cc < prev    next >
C/C++ Source or Header  |  1993-06-14  |  817b  |  68 lines

  1. /*
  2.  * Copyright (C) 1993
  3.  *
  4.  * Department of Computing Science,
  5.  * The University,
  6.  * Newcastle upon Tyne,
  7.  * UK.
  8.  */
  9.  
  10. #ifndef QUEUE_H_
  11. #include "Queue.h"
  12. #endif
  13.  
  14. Queue::Queue ()
  15. {
  16.     head = 0;
  17.     length = 0;
  18. }
  19.  
  20. Queue::~Queue () { delete head; }
  21.  
  22. boolean Queue::IsEmpty ()
  23. {
  24.     if (head == 0)
  25.     return true;
  26.     else
  27.     return false;
  28. }
  29.  
  30. long Queue::QueueSize () { return length; }
  31.  
  32. Job* Queue::Dequeue ()
  33. {
  34.     if (IsEmpty())
  35.     return 0;
  36.  
  37.     List* ptr = head;
  38.     head = head->next;
  39.  
  40.     length--;
  41.     return ptr->work;
  42. }
  43.  
  44. void Queue::Enqueue (Job* toadd)
  45. {
  46.     List* ptr = head;
  47.  
  48.     if (IsEmpty())
  49.     {
  50.     head = new List;
  51.     ptr = head;
  52.     }
  53.     else
  54.     {
  55.     while (ptr->next != 0)
  56.         ptr = ptr->next;
  57.  
  58.     ptr->next = new List;
  59.     ptr = ptr->next;
  60.     }
  61.  
  62.     ptr->next = 0;
  63.     ptr->work = toadd;
  64.     length++;
  65. }
  66.  
  67.     
  68.